package com.adnaan.restaurant.mapper;

import com.adnaan.restaurant.entity.CateGory;
import com.adnaan.restaurant.entity.Evaluation;
import com.adnaan.restaurant.entity.ResOrder;
import com.adnaan.restaurant.entity.ResShop;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 店铺管理Mapper接口
 *
 * @author code_yong
 * @date 2023-09-27
 */
@Mapper
public interface ResShopMapper {
    /**
     * 查询店铺详情
     *
     * @param id 店铺管理主键
     * @return 店铺管理
     */
    @Select("select id, name, address, contact, cover, detail, star, owner_id from res_shop where id = #{id}")
    public ResShop selectResShopById(Long id);

    /**
     * 查询店铺管理列表
     *
     * @param resShop 店铺管理
     * @return 店铺管理集合
     */
    @Select("select id, name, address, contact, cover, star, owner_id from res_shop where name like concat('%',#{shopName},'%')")
    public List<ResShop> selectResShopList(String shopName);


    @Select("select id, name, shop_id from res_category where shop_id = #{shopId}")
    List<CateGory> selectCateGoryByShopId(Long shopId);

    @Select("select id, name, address, contact, cover, star, owner_id from res_shop order by star desc limit 6")
    List<ResShop> hotShop();

    @Update("update res_order_list set star=#{star},evaluate=#{evaluate},status='已完成' where id=#{orderId}")
    int evaluate(Evaluation evaluation);

    @Select("select sum(star) from res_order_list where shop_id=#{sid}")
    int sumStar(@Param("sid") Long shopId);

    @Select("select count(*) from res_order_list where star is not null")
    int countStar();

    @Update("update res_shop set star = #{result} where id = #{sid}")
    int reChangeStar(@Param("result") Double result, @Param("sid") Long shopId);

    @Select("select o.detail,o.user_id,o.evaluate,o.star,o.create_time,u.nick_name userNickname,u.avatar from res_order_list o " +
            "left join sys_user u on u.user_id=o.user_id where o.shop_id=#{sid} and o.evaluate is not null and o.star is not null order by o.star desc")
    List<ResOrder> evalList(@Param("sid") Long shopId);
}
